import {UserActions} from './user';

const initialState = {
  total: 0,
  count: 0,
  current: 0,
  results: [],
};

export const CustomerListActions = {
  CUSTOMER_LIST_UPDATE: 'customer_list_update',
  CUSTOMER_LIST_RESET: 'customer_list_reset',
};

export function updateCustomerList(payload) {
  return {
    type: CustomerListActions.CUSTOMER_LIST_UPDATE,
    payload,
  };
}

export function resetCustomerList(payload) {
  return {
    type: CustomerListActions.CUSTOMER_LIST_RESET,
    payload,
  };
}

export default function customerList(state = initialState, action) {
  switch (action.type) {
    case CustomerListActions.CUSTOMER_LIST_UPDATE:
      return {...state, ...action.payload};
    case CustomerListActions.CUSTOMER_LIST_RESET:
      return initialState;
    case UserActions.USER_SIGN_OUT:
      return {
        total: 0,
        count: 0,
        current: 0,
        results: [],
      };
    default:
      return state;
  }
}
